#!/usr/bin/perl -w
use strict;
use lib 'lib';
use lib 'extlib';
use MT;
use Getopt::Long;

my ($BLOG_ID, $USAGE);

my $MT_PATH = "";

GetOptions("blog=i" => \$BLOG_ID );

$USAGE = <<USAGE
Usage:
mt-rebuild-blog --blog <blog id number>
USAGE
;

sub rebuild_blog
{
        my $mt = $_[0];
        my $blog_id = $_[1];

        $mt->rebuild(
                BlogID => $blog_id,
                EntryCallback => sub { printf("[%d]\t%s\n", $_[0]->id, $_[0]->title); }
        );
}

sub main
{
	my $mt_config = $MT_PATH . 'mt.cfg';
	my $mt = MT->new( Config => $mt_config, Directory => $MT_PATH);
	
	if(defined($BLOG_ID))
	{
		&rebuild_blog($mt, $BLOG_ID);
	}
	else
	{
		print $USAGE;
	}
}

&main();
